package com.business.java2cache.channel;

import java.util.List;

/**
 * 对外提供服务接口
 * Cache Channel
 */
public interface CacheKit {

    /**
     * 从缓存中取数据,先从1级取，再从2级取
     *
     * @param region cache region
     *               key格式：
     *               ehcache：用region,key
     *               memcache：namespace:region:key
     *               redis：使用hashs(region,key)
     * @param key    cache key
     * @return the cached object or null
     */
    public Object get(String region, String key);

    /**
     * 从缓存中取数据,先从1级取，再从2级取
     * region 为空,key的格式
     * ehcache:从默认的region中获取
     * memcache:namespace:key
     * redis:namespace:key
     *
     * @param key cache key
     * @return the cached object or null
     */
    public Object get(String key);


    /**
     * 获取数据,指定缓存的级别level
     *
     * @param level  cache level
     * @param region cache region
     * @param key    cache key
     * @return the cached object or null
     */
    public Object get(int level, String region, String key);

    /**
     * 获取取数据,指定缓存的级别level
     *
     * @param level cache level
     * @param key   cache key
     * @return the cached object or null
     */
    public Object get(int level, String key);


    /**
     * Add an item to the cache
     *
     * @param region
     * @param key     cache key
     * @param value   cache value
     * @param seconds cache Expiration time
     */
    public void set(String region, String key, Object value, int seconds);

    /**
     * Add an item to the cache
     *
     * @param region
     * @param key    cache key
     * @param value  cache value
     *               seconds cache Expiration use default time
     */
    public void set(String region, String key, Object value);

    /**
     * Add an item to the cache
     * region use default value
     *
     * @param key   cache key
     * @param value cache value
     *              seconds cache Expiration use default time
     */
    public void set(String key, Object value);

    /**
     * Add an item to the cache
     * region use default value
     *
     * @param key   cache key
     * @param value cache value
     *              seconds cache Expiration use default time
     */
    public void set(String key, Object value, int seconds);


    /**
     * Add an item to the cache
     *
     * @param level   cache level
     * @param region
     * @param key     cache key
     * @param value   cache value
     * @param seconds cache Expiration time
     */
    public void set(int level, String region, String key, Object value, int seconds);

    /**
     * Add an item to the cache
     *
     * @param level  cache level
     * @param region
     * @param key    cache key
     * @param value  cache value
     *               seconds cache Expiration use default time
     */
    public void set(int level, String region, String key, Object value);

    /**
     * Add an item to the cache
     *
     * @param level cache level
     * @param key   cache key
     * @param value cache value
     *              seconds cache Expiration use default time
     */
    public void set(int level, String key, Object value);

    /**
     * @param key Cache key
     *            Remove an item from the cache
     */
    public void remove(String region, String key);

    /**
     * @param key Cache key
     *            Remove an item from the cache
     */
    public void remove(String key);

    /**
     * Batch remove cache objects
     *
     * @param keys the cache keys to be removeed
     */
    public void remove(String region, List<String> keys);

    /**
     * Batch remove cache objects
     *
     * @param keys the cache keys to be removeed
     */

    public void remove(List<String> keys);

    /**
     * Clear the cache
     */
    public void clear(String region);

    /**
     * update exprie time
     *
     * @param key
     * @param seconds
     */
    public Object exprie(String key, int seconds);

    /**
     * update exprie time
     *
     * @param key
     * @param seconds
     */
    public Object exprie(String region, String key, int seconds);

    public void close();

}
